/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFrame1.java
 *
 * Created on Oct 13, 2011, 2:48:34 PM
 */
package edg2;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Daniel
 */
public class JFrame1 extends javax.swing.JFrame {

    EncadeamentoExterior instance = null;
    List<TabHash> tabHash = null;
    List<Empregado> tabEmpregados = null;
    List<Dependente> tabDependentes = null;
    List codigosGerados = null;
    int numeroRegistrosDependentes, numeroRegistrosEmpregados;

    /** Creates new form JFrame1 */
    public JFrame1() throws IOException {
        instance = new EncadeamentoExterior();
        // instance.criaHash("tabelaEmpregados", 7);
        // instance.criaHash("tabelaDependentes", 7);
        //instance.atualizaRegistrosEmpregadosEDependentes("tabelaEmpregados","tabelaDependentes", 0, 0);
        instance.mostraTotalRegistros("tabelaEmpregados", "tabelaDependentes");
        numeroRegistrosEmpregados = instance.numeroRegistrosEmpregado("tabelaEmpregados");
        numeroRegistrosDependentes = instance.numeroRegistrosDependentes("tabelaDependentes");
        // instance.criaDados("dados");
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        CampoNome = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        CampoIdade = new javax.swing.JTextField();
        LabelSalarioOuCodigoDeEmpregado = new javax.swing.JLabel();
        CampoSalarioOuCodigoDeEmpregado = new javax.swing.JTextField();
        LabelSalarioReais = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        CampoLog = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        LabelCodigoDependente = new javax.swing.JLabel();
        CampoCodigoDependentes = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox4 = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane2 = new javax.swing.JScrollPane();
        CampoLog1 = new javax.swing.JTextArea();
        jLabel14 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jComboBox5 = new javax.swing.JComboBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cadastro de Empregados e Dependentes - ED2");
        setResizable(false);

        jPanel1.setLayout(null);

        jLabel1.setText("Cadastro de Empregados e Dependentes");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(10, 11, 197, 14);

        jLabel2.setText("Tipo:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(10, 35, 24, 14);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Empregado", "Dependente" }));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        jPanel1.add(jComboBox1);
        jComboBox1.setBounds(38, 31, 84, 20);

        jLabel3.setText("Nome:");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(10, 59, 31, 14);

        CampoNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CampoNomeActionPerformed(evt);
            }
        });
        jPanel1.add(CampoNome);
        CampoNome.setBounds(10, 79, 410, 20);

        jLabel5.setText("Idade:");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(10, 110, 40, 20);
        jPanel1.add(CampoIdade);
        CampoIdade.setBounds(10, 130, 180, 20);

        LabelSalarioOuCodigoDeEmpregado.setText("Salário:");
        jPanel1.add(LabelSalarioOuCodigoDeEmpregado);
        LabelSalarioOuCodigoDeEmpregado.setBounds(440, 60, 110, 14);
        jPanel1.add(CampoSalarioOuCodigoDeEmpregado);
        CampoSalarioOuCodigoDeEmpregado.setBounds(440, 80, 290, 20);

        LabelSalarioReais.setText("(R$)");
        jPanel1.add(LabelSalarioReais);
        LabelSalarioReais.setBounds(480, 60, 21, 14);

        jButton1.setText("Cadastrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(440, 130, 90, 23);

        CampoLog.setColumns(20);
        CampoLog.setEditable(false);
        CampoLog.setRows(5);
        jScrollPane1.setViewportView(CampoLog);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(10, 164, 722, 290);

        jTabbedPane1.addTab("Cadastro", jPanel1);

        jPanel2.setLayout(null);

        jLabel6.setText("Consulta de Empregados e Dependentes");
        jPanel2.add(jLabel6);
        jLabel6.setBounds(10, 11, 195, 14);

        jLabel7.setText("Tipo:");
        jPanel2.add(jLabel7);
        jLabel7.setBounds(10, 40, 24, 14);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Empregado", "Dependente" }));
        jComboBox2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox2ItemStateChanged(evt);
            }
        });
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox2);
        jComboBox2.setBounds(40, 40, 84, 20);

        jLabel8.setText("Nome:");
        jPanel2.add(jLabel8);
        jLabel8.setBounds(140, 40, 31, 14);
        jPanel2.add(jTextField1);
        jTextField1.setBounds(180, 40, 194, 20);

        jLabel9.setText("Idade:");
        jPanel2.add(jLabel9);
        jLabel9.setBounds(400, 30, 32, 20);
        jPanel2.add(jTextField2);
        jTextField2.setBounds(550, 30, 50, 20);

        jLabel10.setText("Salário:");
        jPanel2.add(jLabel10);
        jLabel10.setBounds(400, 70, 36, 14);
        jPanel2.add(jTextField3);
        jTextField3.setBounds(550, 70, 130, 20);

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 8));
        jLabel11.setText("(Ex.: 22, <=22, <=22 && >17)");
        jPanel2.add(jLabel11);
        jLabel11.setBounds(550, 0, 110, 40);

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 8));
        jLabel12.setText("(Ex.: 1200.00 , >=1200 && <4000)");
        jPanel2.add(jLabel12);
        jLabel12.setBounds(550, 50, 122, 20);

        jLabel13.setText("Código:");
        jPanel2.add(jLabel13);
        jLabel13.setBounds(140, 80, 37, 14);
        jPanel2.add(jTextField4);
        jTextField4.setBounds(180, 80, 194, 20);

        LabelCodigoDependente.setText("Número de Dependentes:");
        jPanel2.add(LabelCodigoDependente);
        LabelCodigoDependente.setBounds(53, 120, 130, 20);
        jPanel2.add(CampoCodigoDependentes);
        CampoCodigoDependentes.setBounds(284, 120, 90, 20);

        jButton2.setText("Remover");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2);
        jButton2.setBounds(650, 120, 80, 23);

        jButton3.setText("Alterar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton3);
        jButton3.setBounds(550, 120, 80, 23);

        jButton4.setText("Buscar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton4);
        jButton4.setBounds(400, 120, 80, 23);

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Igual", "Maior", "Menor" }));
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox3);
        jComboBox3.setBounds(440, 70, 90, 20);

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Igual", "Maior", "Menor" }));
        jComboBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox4ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox4);
        jComboBox4.setBounds(180, 120, 90, 20);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator1);
        jSeparator1.setBounds(490, 110, 30, 40);

        CampoLog1.setColumns(20);
        CampoLog1.setEditable(false);
        CampoLog1.setRows(5);
        jScrollPane2.setViewportView(CampoLog1);

        jPanel2.add(jScrollPane2);
        jScrollPane2.setBounds(10, 164, 722, 290);

        jLabel14.setText("Código:");
        jPanel2.add(jLabel14);
        jLabel14.setBounds(500, 100, 50, 20);
        jPanel2.add(jTextField5);
        jTextField5.setBounds(500, 120, 40, 20);
        jPanel2.add(jSeparator2);
        jSeparator2.setBounds(400, 100, 350, 30);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator3);
        jSeparator3.setBounds(640, 120, 30, 20);

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Igual", "Maior", "Menor" }));
        jComboBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox5ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox5);
        jComboBox5.setBounds(440, 30, 90, 20);

        jTabbedPane1.addTab("Consulta", jPanel2);

        jMenu1.setText("Arquivo");

        jMenuItem2.setText("Sair");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Ajuda");

        jMenuItem1.setText("Sobre");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
    if (jComboBox1.getSelectedIndex() == 0) {
        LabelSalarioOuCodigoDeEmpregado.setText("Salário");
        LabelSalarioReais.setVisible(true);
    }
    if (jComboBox1.getSelectedIndex() == 1) {
        LabelSalarioOuCodigoDeEmpregado.setText("Nome do Empregado");
        LabelSalarioReais.setVisible(false);
    }
}//GEN-LAST:event_jComboBox1ItemStateChanged

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    if (CampoSalarioOuCodigoDeEmpregado.getText().compareTo("") == 0
            || CampoNome.getText().compareTo("") == 0 || CampoIdade.getText().compareTo("") == 0) {
        CampoLog.setText("Campos em branco" + "\n");
    } else {
        if (jComboBox1.getSelectedIndex() == 0) {
            try {
                instance.insereEmpregado(CampoNome.getText(), Integer.parseInt(CampoIdade.getText()), Double.parseDouble(CampoSalarioOuCodigoDeEmpregado.getText()), "tabelaEmpregados", "dadosEmpregados", numeroRegistrosEmpregados);
                numeroRegistrosEmpregados++;
                instance.atualizaRegistrosEmpregadosEDependentes("tabelaEmpregados", "tabelaDependentes", numeroRegistrosEmpregados, numeroRegistrosDependentes);
                CampoLog.setText(CampoLog.getText() + "Cadastrado Empregado: " + instance.emp.codEmpregado + " " + CampoNome.getText()
                        + " " + CampoIdade.getText() + " " + CampoSalarioOuCodigoDeEmpregado.getText() + "\n");

            } catch (Exception ex) {
                Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        if (jComboBox1.getSelectedIndex() == 1) {
            try {
                if (instance.insereDependente(CampoNome.getText(), Integer.parseInt(CampoIdade.getText()),
                        (CampoSalarioOuCodigoDeEmpregado.getText()), "tabelaDependentes", "dadosDependentes", numeroRegistrosDependentes) != -1) {
                    numeroRegistrosDependentes++;
                    instance.atualizaRegistrosEmpregadosEDependentes("tabelaEmpregados", "tabelaDependentes", numeroRegistrosEmpregados, numeroRegistrosDependentes);
                    CampoLog.setText(CampoLog.getText() + "Cadastrado Dependente: " + instance.dep.codDependente + " " + CampoNome.getText()
                            + " " + CampoIdade.getText() + " " + CampoSalarioOuCodigoDeEmpregado.getText() + "\n");
                } else {
                    CampoLog.setText("Empregado nao encontrado" + "\n");
                }
            } catch (Exception ex) {
                Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        CampoNome.setText("");
        CampoIdade.setText("");
        CampoSalarioOuCodigoDeEmpregado.setText("");
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox2ItemStateChanged
    if (jComboBox2.getSelectedIndex() == 0) {
        LabelCodigoDependente.setText("Numero de Dependentes:");
        jLabel10.setVisible(true);
        jLabel12.setVisible(true);
        jComboBox3.setVisible(true);
        jTextField3.setVisible(true);
    }
    if (jComboBox2.getSelectedIndex() == 1) {
        LabelCodigoDependente.setText("     Código do Empregado:");
        jLabel10.setVisible(false);
        jLabel12.setVisible(false);
        jComboBox3.setVisible(false);
        jTextField3.setVisible(false);
    }
}//GEN-LAST:event_jComboBox2ItemStateChanged

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    new JFrameAbout().setVisible(true);
}//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void CampoNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CampoNomeActionPerformed
        int posicao, codigo, aux, tamHash = 26;
        String nome;
        int salario, idade;
        nome = CampoNome.getText();
        idade = Integer.parseInt(CampoIdade.getText());
        salario = Integer.parseInt(CampoSalarioOuCodigoDeEmpregado.getText());
        char primLetra = nome.charAt(0);
        /*
         * Precisamos descobrir a posição do caracter no alfabeto para fazer o cálculo do HashCode.
         * Para tal, subtraimos a primeira letra do nome pelo caracter 'a'.
         */
        aux = ((primLetra - 'a') + 1);
        posicao = (aux % tamHash);
        tabHash.add(new TabHash(posicao));
        do {
            codigo = (int) (Math.random() * (aux));
        } while (codigosGerados.contains(codigo));
        codigosGerados.add(codigo);
        //  tabEmpregados.add(new Empregado(codigo, nome, idade, salario, -1, true));
    }//GEN-LAST:event_CampoNomeActionPerformed

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ActionPerformed

    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox3ActionPerformed

    private void jComboBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox4ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox4ActionPerformed

//    public void mostraBusca() throws FileNotFoundException, IOException{
//        RandomAccessFile aux = null;
//        try{
//        aux = new RandomAccessFile("dadosBusca","rw" );
//        if (aux != null){
//        aux.seek(0);
//        
//        }
//        }
//        catch (IOException e) {
//        } finally {
//        if(aux != null)
//            aux.close();
//        }
//    }
//    
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        CampoLog1.setText("");
        if (jComboBox2.getSelectedIndex() == 0) {
            try {
                if (jTextField4.getText().compareTo("") != 0) {
                    if (instance.buscaEmpregado(Integer.parseInt(jTextField4.getText()), "tabelaEmpregados", "dadosEmpregados") != -1) {
                        CampoLog1.append("Código: " + instance.emp.codEmpregado + " Nome: " + instance.emp.nome + " Salario: " + instance.emp.salario + " Idade: " + instance.emp.idade
                                + "\n");
                    } else {
                        CampoLog1.append("Nenhum registro encontrado" + "\n");
                    }

                } else {
                    instance.buscaEmpregado(jTextField1.getText(), jTextField3.getText(), jTextField2.getText(), "tabelaEmpregados", "dadosEmpregados");
                    if (instance.resultadoBusca.compareTo("") != 0) {
                        CampoLog1.append(instance.resultadoBusca);
                    } else {
                        CampoLog1.append("Nenhum registro encontrado" + "\n");
                    }
                }
            } catch (Exception ex) {
                Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);
            }
//            try {
//                if(instance.buscaEmpregado(Integer.parseInt(jTextField4.getText()), "tabelaEmpregados", "dadosEmpregados") != -1){
//                CampoLog1.append("Código: "+instance.emp.codEmpregado+" Nome: "+instance.emp.nome+" Salario: " + instance.emp.salario+" Idade: "+instance.emp.idade
//                        +"\n");
//                }
//                else{
//                    CampoLog1.append("Registro não encontrado!" + "\n");
//                }
//            } catch (Exception ex) {
//                Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);
//             
//            }
        }

        if (jComboBox2.getSelectedIndex() == 1) {
            try {
                if (jTextField4.getText().compareTo("") != 0) {
                    if (instance.buscaDependente(Integer.parseInt(jTextField4.getText()), "tabelaDependentes", "dadosDependentes") != -1) {
                        CampoLog1.append("Código: " + instance.dep.codDependente + " Nome: " + instance.dep.nome + " Idade: " + instance.dep.idade + " Código Do Empregado: "
                                + instance.dep.codEmpregado + "\n");
                    } else {
                        CampoLog1.append("Nenhum registro encontrado" + "\n");
                    }

                } else {
                    instance.buscaDependente(jTextField1.getText(), CampoCodigoDependentes.getText(), jTextField2.getText(), "tabelaDependentes", "dadosDependentes");
                    if (instance.resultadoBusca.compareTo("") != 0) {
                        CampoLog1.append(instance.resultadoBusca);
                    } else {
                        CampoLog1.append("Nenhum registro encontrado" + "\n");
                    }
                }


//                if(instance.buscaDependente(Integer.parseInt(jTextField4.getText()), "tabelaDependentes", "dadosDependentes") != -1){
//                CampoLog1.append("Código: "+instance.dep.codDependente+" Nome: "+instance.dep.nome+" Idade: "+instance.dep.idade+" Código Do Empregado: "+
//                        instance.dep.codEmpregado +"\n");
//                }
//                else{
//                    CampoLog1.append("Registro não encontrado!" + "\n");
//                }
            } catch (Exception ex) {
                Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);

            }
        }

    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        Alterar.setType(jComboBox2.getSelectedIndex(), Integer.parseInt(jTextField5.getText()));
        new Alterar().setVisible(true);

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        if (jComboBox2.getSelectedIndex() == 0) {
            try {
                if (instance.excluiEmpregado(Integer.parseInt(jTextField5.getText()), "tabelaEmpregados", "dadosEmpregados") != -1) {
                    numeroRegistrosEmpregados--;
                    instance.atualizaRegistrosEmpregadosEDependentes("tabelaEmpregados", "tabelaDependentes", numeroRegistrosEmpregados, numeroRegistrosDependentes);
                    CampoLog1.append("Registro excluido com sucesso"
                            + "\n");
                } else {
                    CampoLog1.append("Registro não encontrado!" + "\n");
                }
            } catch (Exception ex) {
                Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if (jComboBox2.getSelectedIndex() == 1) {
            try {
                if (instance.buscaDependente(Integer.parseInt(jTextField4.getText()), "tabelaDependentes", "dadosDependentes") != -1) {
                    numeroRegistrosDependentes--;
                    instance.atualizaRegistrosEmpregadosEDependentes("tabelaEmpregados", "tabelaDependentes", numeroRegistrosEmpregados, numeroRegistrosDependentes);
                    CampoLog1.append("Registro excluido com sucesso " + "\n");
                } else {
                    CampoLog1.append("Registro não encontrado!" + "\n");
                }
            } catch (Exception ex) {
                Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);

            }
        }


    }//GEN-LAST:event_jButton2ActionPerformed

    private void jComboBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox5ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new JFrame1().setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(JFrame1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CampoCodigoDependentes;
    private javax.swing.JTextField CampoIdade;
    private javax.swing.JTextArea CampoLog;
    private javax.swing.JTextArea CampoLog1;
    private javax.swing.JTextField CampoNome;
    private javax.swing.JTextField CampoSalarioOuCodigoDeEmpregado;
    private javax.swing.JLabel LabelCodigoDependente;
    private javax.swing.JLabel LabelSalarioOuCodigoDeEmpregado;
    private javax.swing.JLabel LabelSalarioReais;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
}
